package client.ui.component.navigation;

import client.ui.component.layout.VFlowLayout;
import client.ui.util.MaterialColors;

import javax.swing.*;
import java.awt.*;

/**
  * @Description 导航组件
  * @author 孔明浩
  * @Date 2020/3/21
  */
public class Navigation extends JPanel {
    //导航栏
    protected JPanel navigatorBar;
    //内容面板
    protected JPanel contentPanel;
    //菜单面板
    protected JPanel menuPanel;
    //用户信息面板
    protected JPanel userPanel;
    private GridBagLayout gridBagLayout= new GridBagLayout();

    public Navigation(JPanel navigatorBar,JPanel contentPanel, JPanel menuPanel, JPanel userPanel){
        super();
        if (navigatorBar == null){
            this.navigatorBar = new JPanel(new VFlowLayout(VFlowLayout.TOP));
        } else {
            this.navigatorBar = navigatorBar;
        }
        if (contentPanel == null){
            this.contentPanel = new JPanel(new CardLayout());
        } else {
            this.contentPanel = contentPanel;
        }
        if (menuPanel == null){
            this.menuPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        } else {
            this.menuPanel = menuPanel;
        }
        if (userPanel == null){
            this.userPanel = new JPanel();
        } else {
            this.userPanel = userPanel;
        }
        this.setLayout(gridBagLayout);
        initial();
    }

    protected void initial(){
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = GridBagConstraints.WEST;
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new Insets(0,0,0,0);
        gridBagLayout.setConstraints(userPanel, gridBagConstraints);
        userPanel.setBackground(MaterialColors.COSMO_BLACK);
        userPanel.setPreferredSize(new Dimension(200,300));
        this.add(userPanel);

        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.anchor = GridBagConstraints.WEST;
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.fill = GridBagConstraints.BOTH;
        navigatorBar.setBackground(MaterialColors.COSMO_BLACK);
        gridBagLayout.setConstraints(navigatorBar, gridBagConstraints);
        this.add(navigatorBar);

        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.anchor = GridBagConstraints.SOUTHWEST;
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagLayout.setConstraints(menuPanel, gridBagConstraints);
        menuPanel.setBackground(MaterialColors.COSMO_BLACK);
        menuPanel.setPreferredSize(new Dimension(200,40));
        this.add(menuPanel);

        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.anchor = GridBagConstraints.CENTER;
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridheight = 3;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.fill = GridBagConstraints.BOTH;
        gridBagLayout.setConstraints(contentPanel, gridBagConstraints);
        contentPanel.setBackground(MaterialColors.COSMO_STRONG_GRAY);
        this.add(contentPanel);
    }

}
